<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Add a (signed) amount of time to a field</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.intlcalendar.html">IntlCalendar</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="intlcalendar.after.html">IntlCalendar::after</a></div>
 <div class="up"><a href="class.intlcalendar.html">IntlCalendar</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="intlcalendar.add" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">IntlCalendar::add</h1>
  <p class="verinfo">(PHP 5.5.0, PECL &gt;= 3.0.0a1)</p><p class="refpurpose"><span class="refname">IntlCalendar::add</span> &mdash; <span class="dc-title">Add a (signed) amount of time to a field</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-intlcalendar.add-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>IntlCalendar::add</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$field</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$amount</code></span>
   )</div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>intlcal_add</strong></span>
    ( <span class="methodparam"><span class="type"><a href="class.intlcalendar.html" class="type IntlCalendar">IntlCalendar</a></span> <code class="parameter">$cal</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$field</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$amount</code></span>
   )</div>

  <p class="para rdfs-comment">
   Add a signed amount to a field. Adding a positive amount allows advances in
   time, even if the numeric value of the field decreases (e.g. when working
   with years in BC dates).
  </p>
  <p class="para">
   Other fields may need to adjusted – for instance, adding a month to the 31st
   of January will result in the 28th (or 29th) of February. Contrary to
   <span class="function"><a href="intlcalendar.roll.html" class="function">IntlCalendar::roll()</a></span>, when a value wraps around, more
   significant fields may change. For instance, adding a day to the 31st of
   January will result in the 1st of February, not the 1st of Janurary.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-intlcalendar.add-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<em><code class="parameter">cal</code></em></dt>

    <dd>

     <p class="para">
      The IntlCalendar resource.
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">field</code></em></dt>

    <dd>

     

<p class="para">
 One of the <a href="class.intlcalendar.html" class="classname">IntlCalendar</a> date/time <a href="class.intlcalendar.html#intlcalendar.constants" class="link">field constants</a>. These are integer
 values between <em>0</em> and
 <strong><code>IntlCalendar::FIELD_COUNT</code></strong>.
</p>

    </dd>

   
   
    <dt>
<em><code class="parameter">amount</code></em></dt>

    <dd>

     <p class="para">
      The signed amount to add to the current field. If the amount is positive,
      the instant will be moved forward; if it is negative, the instant wil be
      moved into the past. The unit is implicit to the field type. For instance,
      hours for <strong><code>IntlCalendar::FIELD_HOUR_OF_DAY</code></strong>.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-intlcalendar.add-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <strong><code>TRUE</code></strong> on success 或者在失败时返回 <strong><code>FALSE</code></strong>.
  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-intlcalendar.add-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2526">
   <p><strong>Example #1 <span class="function"><strong>IntlCalendar::add()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'intl.default_locale'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'fr_FR'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'date.timezone'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'UTC'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$cal&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">IntlGregorianCalendar</span><span style="color: #007700">(</span><span style="color: #0000BB">2012</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0&nbsp;</span><span style="color: #FF8000">/*&nbsp;January&nbsp;*/</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">31</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">formatObject</span><span style="color: #007700">(</span><span style="color: #0000BB">$cal</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$cal</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlCalendar</span><span style="color: #007700">::</span><span style="color: #0000BB">FIELD_MONTH</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">formatObject</span><span style="color: #007700">(</span><span style="color: #0000BB">$cal</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$cal</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlCalendar</span><span style="color: #007700">::</span><span style="color: #0000BB">FIELD_DAY_OF_MONTH</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">formatObject</span><span style="color: #007700">(</span><span style="color: #0000BB">$cal</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
31 janv. 2012 00:00:00
29 févr. 2012 00:00:00
1 mars 2012 00:00:00
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.intlcalendar.html">IntlCalendar</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="intlcalendar.after.html">IntlCalendar::after</a></div>
 <div class="up"><a href="class.intlcalendar.html">IntlCalendar</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
